#!/bin/bash

source src/conf/config.conf

mkdir -p /var/www/tftp

dpkg-reconfigure dash

apt-get install -y samba lighttpd dnsmasq nfs-kernel-server wget tcpdump nmap unzip

cp /etc/samba/smb.conf /etc/samba/smb.conf.old
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.old
cp /etc/exports  /etc/exports.old
cp /etc/inetd.conf /etc/inetd.conf.old
cp /etc/network/interfaces /etc/network/interfaces.old

cd src/conf/
cat smb >> /etc/samba/smb.conf
cat dnsmasq >> /etc/dnsmasq.conf
cat export >> /etc/exports
cat network >> /etc/network/interfaces

cd ../../
cat > /etc/inetd.conf << EOF
tftp          dgram   udp     wait    root  /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/www/tftp
EOF

#cp /etc/default/tftpd-hpa /etc/default/tftpd-hpa.old
#cat conf/tftpd-hpa > /etc/default/tftpd-hpa
#/etc/init.d/tftpd-hpa restart
#cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.old
#cat conf/dhcp.txt >> /etc/dhcp3/dhcpd.conf
 
#cat > /etc/iptables.rules << EOF
#/sbin/input -A INPUT -s 192.168.1.0/24 -m tcp -p tcp --dport 69 -j ACCEPT
#EOF
#iptables -A INPUT -m state --state NEW -i eth0 -p udp --dport 69 -j ACCEPT
#iptables -A OUTPUT -m state --state NEW -o eth0 -p udp --dport 69 -j ACCEPT
#iptables-save > /etc/iptables.up.rules
#iptables-save > /etc/iptables.rules
#cat > /etc/network/if-pre-up.d/iptables << EOF
#/sbin/iptables-restore < /etc/iptables.up.rules
#EOF
#chmod +x /etc/network/if-pre-up.d/iptables

iptables -L
#/etc/init.d/dhcp3-server restart

/etc/init.d/nfs-kernel-server restart
cd /var/www/
chmod -R a+r *
dnsmasq
/etc/init.d/samba restart
/etc/init.d/networking restart
pgrep -lf tftpd
ps ax | grep [t]ftp
